<template>
  <div class="sti-ffWoodIndustry-container">
    <div class="sti-ffWoodIndustry-chart" id="sti-ffWoodIndustry-chart"></div>
  </div>
</template>

<script>
import echarts from 'echarts'
export default {
  name: 'components-stiffWoodIndustry',
  props: ['dataValue'],
  data() {
    return {
      arrIndustryData: []
    }
  },
  methods: {
    getData() {
      let label = [];
      let data = [];
      this.arrIndustryData.map(d => {
        label.push(d.name);
        data.push(d.value);
      })
      this.setOption(label, data)
    },
    setOption(label, data) {
      let myChart = echarts.init(document.getElementById('sti-ffWoodIndustry-chart'))
      let option = {
        color: ['#3398DB'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        xAxis: [
          {
            type: 'category',
            data: label,
            axisTick: {
                alignWithLabel: true
            },
            axisLabel: {
              color: '#5ABDFF',
              fontSize: 14
            },
            splitLine: {
              lineStyle: {
                color: '#2C4474',
                type: 'solid',
                width: 1
              }
            },
            axisLine: {
              lineStyle: {
                color: '#2C4474',
                type: 'solid',
                width: 1
              }
            }
          }
        ],
        yAxis: [
          {
            type: 'value',
            minInterval: 1,
            axisLabel: {
              color: '#5ABDFF',
              fontSize: 14,
              formatter: (value, index) => {
                  if (value >= 1000) {
                      value = (value / 1000) + 'k'
                  }
                  return value
              }
            },
            splitLine: {
              lineStyle: {
                color: '#2C4474',
                type: 'solid',
                width: 1
              }
            },
            axisLine: {
              lineStyle: {
                color: '#2C4474',
                type: 'solid',
                width: 1
              }
            }
          }
        ],
        series: [
          {
            name: '行业分布',
            type: 'bar',
            data: data,
            barMaxWidth: 20,
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0, 0, 0, 1,
                  [
                    {offset: 0, color: 'rgba(41, 215, 250, .9)'},
                    {offset: 1, color: 'rgba(30, 60, 88, .9)'}
                  ]
                )
              }
            }
          }
        ]
      }
      myChart.setOption(option)
      myChart.resize()
    }
  },
  mounted() {
    this.getData()
  },
  created() {
    this.arrIndustryData = this.dataValue.slice(0, 5)
  }
}
</script>

<style lang="less">
.sti-ffWoodIndustry-container {
  width: 100%;
  height: 100%;
  .sti-ffWoodIndustry-chart {
    width: 100%;
    height: 100%;
  }
}
</style>
